<?php
namespace app\models;
use Phalcon\Mvc\Model;

class Base extends Model
{
    private $_propertyAnnotations = [];
    /** @var array  $_notes 注释数组*/
    private $_notes = [];

    public function getNotes(){
        if(empty($this->_notes)) {
            $this->prepareAnnotation();

            foreach ($this->_propertyAnnotations as $property => $annotation) {
                if ($annotation->has('Note')) {
                    $this->_notes[$property] = $annotation->get('Note')->getArgument(0);
                }

            }
        }
        return $this->_notes;
    }

    public function getNote($name){
        $notes = $this->getNotes();
        return isset($notes[$name])?$notes[$name]:'';
    }

    protected function prepareAnnotation()
    {
        if(empty($this->_propertyAnnotations)) {
            /** @var  $annotationsService \Phalcon\Annotations\Adapter/Files */
            $annotationsService = $this->getDI()->getShared('annotations');
            /** @var  $handlerAnnotations \Phalcon\Annotations\Reflection */
            $handlerAnnotations = $annotationsService->get(get_called_class());

            /** @var $propertyAnnotations \Phalcon\Annotations\Collection[] */
            $this->_propertyAnnotations = $handlerAnnotations->getPropertiesAnnotations();
        }
    }
}
